<template>
	<view class="columnbox wdh-100 content">
		<view class="rowbox wdh-100 search-box">
			<view class="rowbox search-info spb">
				<view class="rowbox">
					<u-icon name="search" size="40rpx"></u-icon>
					<input placeholder="搜索患者" />
				</view>
				<view class="rowbox search-btn">搜索</view>
			</view>
		</view>
		<view style="margin-top:20rpx;width: 100%;"></view>
		<view @click="showDetail(item)" class="wdh-100 rowbox spb info-box" v-for="(item,index) in list" :key='index'>
			<view class="rowbox">
				<image class="user-img" mode="aspectFill" src="https://zhongyi.jiayixunfang.cn/upload/logo.png"></image>
				<view class="columnbox als info-detail">
					<view class="user-name">{{item.name}}</view>
					<view class="rowbox info-content textovflow">
						<image src="/static/img/girl.png" mode="widthFix" v-if="item.sex==2"></image>
						<image src="/static/img/boy.png" mode="widthFix" v-else></image>
						<view> {{item.age}}岁｜{{item.phone}}</view>
					</view>
				</view>
			</view>
			<view class="columnbox status-box">
				<!-- <view class="info-date">2024-04-10 复诊</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageNo: 1,
				list: [],
				total: 0,
				from: ''
			};
		},
		onLoad(options) {
			if (options.from) {
				this.from = options.from
			}
			this.getList()
		},
		methods: {
			showDetail(v) {
				if (this.from == 'goods') {
					let pages = getCurrentPages(); //获取所有页面栈实例列表
					let nowPage = pages[pages.length - 1]; //当前页页面实例
					let prevPage = pages[pages.length - 2]; //上一页页面实例
					prevPage.$vm.memberid = v.memberid
					prevPage.$vm.userid = v.id
					prevPage.$vm.name = v.name
					uni.navigateBack()
				} else {
					uni.navigateTo({
						url: '/packageA/yaofang/kaifang?id=' + v.id
					})
				}
			},
			getList() {
				this.$req.post('/doctor/patients', {
					pageNo: this.pageNo,
					pageSize: 20,
					doctorid: uni.getStorageSync('uid'),
					name: ''
				}).then(res => {
					res.data.data.data.forEach(v => {
						v.age = this.getAge(v.shengri)
					})
					this.list = this.list.concat(res.data.data.data)
					this.total = res.data.data.totalCount
				})
			},
			getAge(birthday) {
				var today = new Date();
				var birthDate = new Date(birthday);
				var age = today.getFullYear() - birthDate.getFullYear();
				var monthDiff = today.getMonth() - birthDate.getMonth();
				if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
					age--;
				}
				return age - 1;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F5F8FB;
		min-height: 100vh;
		justify-content: flex-start;
		font-family: PingFang SC;
	}

	.info-box {
		padding: 32rpx 36rpx;
		background: #fff;

	}

	.group-title {
		font-size: 28rpx;
		color: #202020;
		font-weight: bold;

		image {
			width: 40rpx;
			height: 40rpx;
			margin-right: 10rpx;
		}
	}

	.chat-title {
		font-size: 32rpx;
		padding: 0 36rpx;
		padding-top: 32rpx;
		background: #fff;
		margin-top: 20rpx;
		color: #232323;
		font-weight: bold;
	}

	.user-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 100rpx;
		margin-right: 20rpx;
	}

	.info-detail {
		line-height: 40rpx;

		.user-name {
			font-size: 30rpx;
			color: #202020;
		}

		.info-content {
			font-size: 24rpx;
			color: #9B9B9B;
			margin-top: 10rpx;

			image {
				width: 24rpx;
				height: 24rpx;
				margin-right: 10rpx;
			}
		}
	}

	.status-box {
		align-items: flex-end;

		.info-date {
			font-size: 24rpx;
			color: #606062;
			margin-top: 50rpx;
		}

		.status-btn {
			font-size: 22rpx;
			color: #fff;
			padding: 4rpx 10rpx;
			margin-top: 14rpx;
			border-radius: 10rpx;
		}
	}

	.search-box {
		padding: 32rpx 36rpx;
		background: #fff;

		.search-info {
			width: 100%;
			height: 70rpx;
			border: #00b6b2 solid 1px;
			border-radius: 100rpx;
			padding-left: 20rpx;

			input {
				font-size: 26rpx;
				margin-left: 10rpx;
			}
		}

		.search-btn {
			width: 110rpx;
			height: 50rpx;
			background: linear-gradient(to right, #01a7a1, #5acbc1);
			border-radius: 100rpx;
			font-size: 26rpx;
			color: #fff;
			margin-right: 10rpx;
		}
	}
</style>